#!/bin/bash
##USB性能测试
test_usb_rw(){
	if [[ $mode == 'auto' ]];then
		test_usb_path=${test_usb_path}
	else
		input '请输入usb设备分区挂载目录,默认[ /usb/ ]' test_usb_path
		input_check "$test_usb_path" "USB设备分区设置" '/usb/' test_usb_path
	fi
	if [[ -d "$test_usb_path" ]];then
		pushd $test_usb_path
		test_usb_path=`pwd`
		red_z_green_z '正在测试---->' '[ 4k ]'
		red_z_green_z "执行命令---->" "[ dd if=/dev/zero of=${test_usb_path}/usbtest bs=4k count=800000 ]"
		red_z_green_z "如需终止请执行--------->" "[ sudo kill -9 $$ ]"
		dd if=/dev/zero of=${test_usb_path}/usbtest bs=4k count=800000
		rm -f ${test_usb_path}/usbtest

		red_z_green_z '\n正在测试---->' '[ 8k ]'
		red_z_green_z "执行命令---->" "[ dd if=/dev/zero of=${test_usb_path}/usbtest bs=8k count=400000 ]"
		red_z_green_z "如需终止请执行--------->" "[ sudo kill -9 $$ ]"
		dd if=/dev/zero of=${test_usb_path}/usbtest bs=8k count=400000
		rm -f ${test_usb_path}/usbtest

		red_z_green_z '\n正在测试---->' '[ 16k ]'
		red_z_green_z "执行命令---->" "[ dd if=/dev/zero of=${test_usb_path}/usbtest bs=16k count=200000	]"
		red_z_green_z "如需终止请执行--------->" "[ sudo kill -9 $$ ]"
		dd if=/dev/zero of=${test_usb_path}/usbtest bs=16k count=200000	
		rm -f ${test_usb_path}/usbtest

		red_z_green_z '\n正在测试---->' '[ 32k ]'
		red_z_green_z "执行命令---->" "[ dd if=/dev/zero of=${test_usb_path}/usbtest bs=32k count=100000 ]"
		red_z_green_z "如需终止请执行--------->" "[ sudo kill -9 $$ ]"
		dd if=/dev/zero of=${test_usb_path}/usbtest bs=32k count=100000
		rm -f ${test_usb_path}/usbtest

		red_z_green_z '\n正在测试---->' '[ 64k ]'
		red_z_green_z "执行命令---->" "[ dd if=/dev/zero of=${test_usb_path}/usbtest bs=64k count=50000 ]"
		red_z_green_z "如需终止请执行--------->" "[ sudo kill -9 $$ ]"
		dd if=/dev/zero of=${test_usb_path}/usbtest bs=64k count=50000
		rm -f ${test_usb_path}/usbtest

		red_z_green_z '\n正在测试---->' '测试完成'
	else
		red_bg "路径不存在: [ $test_usb_path ]"
	fi
}
if [[ "$1" == 'f' ]];then
    if [[ -e './item.sh' ]];then
        source ./item.sh
    else
        echo -e "请进入目录:[ spzx/ ]再执行脚本"
    fi
    test_usb_rw
else
    if [[ -z "$1" ]];then
        echo -e "请在脚本执行的后面加上一个参数直接进行测试，例如--> [ bash spzx/test/usb.sh f ]"
    fi
fi